Shader "Prota/GaussianBlurSinglePassVertical"
{
    Properties
    {
        [Toggle] _USE_MAIN_TEX ("Use MainTex", Float) = 0
        _MainTex ("MainTex", 2D) = "white" { }
        _BlitTexture ("BlitTex", 2D) = "white" { }
        _Mult ("Mult", float) = 1
    }
    SubShader
    {
        Cull Off ZWrite Off ZTest Always

        Blend SrcAlpha OneMinusSrcAlpha
        
        Pass
        {
            CGPROGRAM
            #pragma shader_feature _USE_MAIN_TEX_ON
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }
            
            #if _USE_MAIN_TEX_ON
            sampler2D _MainTex;
            float4 _MainTex_TexelSize;
            #endif
            
            #if !_USE_MAIN_TEX_ON
            sampler2D _BlitTexture;
            float4 _BlitTexture_TexelSize;
            #endif
            
            float _Mult;
            
            static const float c[] ={
                0.011, 0.022, 0.032, 0.027, 0.025, 0.033, 0.045, 0.063, 0.09, 0.13, 0.17, 0.21
            };
            
            float4 frag (v2f v) : SV_Target
            {
                #if _USE_MAIN_TEX_ON
                sampler2D tex = _MainTex;
                float2 texel = _MainTex_TexelSize.xy;
                #else
                sampler2D tex = _BlitTexture;
                float2 texel = _BlitTexture_TexelSize.xy;
                #endif
                
                float4 total = float4(0.0, 0.0, 0.0, 0.0);
                float sum = 0.0;
                
                for(int i = -11; i <= 11; i++)
                {
                    int k = 11 - abs(i);
                    float2 offset = float2(0, i * texel.y);
                    total += c[k] * tex2D(tex, v.uv + offset);
                    sum += c[k];
                }
                
                return total / sum * _Mult;
            }
            ENDCG
        }
    }
}
